<%@ page language="java" pageEncoding="UTF-8"%>

<script language="javascript" type="text/javascript">
	function changeSelect() {
		var va = document.getElementById("drop").value;
		topage(va);
	}
	function topage(page) {
		var form = document.forms[0];
		if (page > 0) {
			form.pageNo.value = page;
			form.submit();
		}
	}
	function topageClass(page, index) {
		var form = document.forms[0];
		$(".a").removeClass('page_num active');
		$("#index").addClass('page_num active');
		if (page > 0) {
			form.pageNo.value = page;
			form.submit();
		}
	}
	$(function() {
		var totalPage = '<s:property value="#page.totalPage"/>';
		var currentPage = '<s:property value="#page.currentPage"/>';
		$("#pageDivId").empty();
		$("#pageDivId").append(linkedPage(totalPage, currentPage));
	});

	function linkedPage(totalPage, currentPage) {

		var currentPage = parseInt(currentPage);//当前页
		var totalPage = parseInt(totalPage);//总页数
		var content = '';
		content += '<div class="clearfix" id="pageDivId"><p class="page r"><span class="pre_page">';
		if (currentPage > 1) {
			content = content + '<a href="javascript:topageClass('
					+ (currentPage - 1) + ');">上一页</a></span>';
		} else {
			content = content + '上一页</span>';
		}
		
		if(totalPage>6){
			if (currentPage < 4) {
				for (var i = 1; i <= 4; i++) {
					if (currentPage == i) {
						content = content + '<a href="javascript:topageClass('
								+ i + ');" class="page_num active"id="' + i
								+ '">' + i + '</a>';
					} else {
						content = content + '<a href="javascript:topageClass('
								+ i + ');" class="page_num"  id="' + i + '">'
								+ i + '</a>';
					}
				}
			}else if(currentPage == 4){
				for (var i = 1; i <= 4; i++) {
					if (currentPage == i) {
						content = content + '<a href="javascript:topageClass('
								+ i + ');" class="page_num active"id="' + i
								+ '">' + i + '</a>';
					} else {
						content = content + '<a href="javascript:topageClass('
								+ i + ');" class="page_num"  id="' + i + '">'
								+ i + '</a>';
					}
				}
			}else{
				content = content + '<a href="javascript:topageClass(\'1\');" class="page_num" id="1">' + 1 + '</a>';
				content = content + '<span class="page_num" >'+ "..." + '</span>';
				if(currentPage==totalPage){
				content = content + '<a href="javascript:topageClass('
				 		  + (currentPage-3) + ');" class="page_num"  id="' + (currentPage-2) + '">'
						  + (currentPage-3) + '</a>';
				}
				content = content + '<a href="javascript:topageClass('
				 		  + (currentPage-2) + ');" class="page_num"  id="' + (currentPage-2) + '">'
						  + (currentPage-2) + '</a>';
				content = content + '<a href="javascript:topageClass('
				 		  + (currentPage-1) + ');" class="page_num"  id="' + (currentPage-1) + '">'
						  + (currentPage-1) + '</a>';
				content = content + '<a href="javascript:topageClass('
				 		  + currentPage + ');" class="page_num active"  id="' + currentPage + '">'
						  + currentPage + '</a>';
			}
			if(currentPage!=totalPage && currentPage>3){
				content = content + '<a href="javascript:topageClass('
				 		  + (currentPage+1) + ');" class="page_num"  id="' + (currentPage+1) + '">'
						  + (currentPage+1) + '</a>';
			}
			if(currentPage + 2 >= totalPage){
				if(currentPage+2==totalPage){
					content = content + '<a href="javascript:topageClass('
			 		  + (currentPage+2) + ');" class="page_num"  id="' + (currentPage+2) + '">'
					  + (currentPage+2) + '</a>';
				}
			}else{
				content = content + '<span class="page_num" >'+ "..." + '</span>';
				content = content + '<a href="javascript:topageClass('
		 		  + totalPage + ');" class="page_num"  id="' + totalPage + '">'
				  + totalPage + '</a>';
			}
		}else {
			for (var i = 1; i <= totalPage; i++) {
				if (currentPage == i) {
					content = content + '<a href="javascript:topageClass(' + i
							+ ');" class="page_num active"id="' + i + '">' + i
							+ '</a>';
				} else {
					content = content + '<a href="javascript:topageClass(' + i
							+ ');" class="page_num" id="' + i + '">' + i
							+ '</a>';
				}
			}
		}
		content = content + '<span class="next_page">';
		if (currentPage < totalPage) {
			content = content + '<a href="javascript:topageClass('
					+ (currentPage + 1) + ');">下一页</a></span>';
		} else {
			content = content + '下一页</span>';
		}
		content += '</p></div>';
		return content;

	}
</script>
<s:if test="#page.totalPage>0">
	<div class="clearfix" id="pageDivId">
		<p class="page r">
			<span class="pre_page"> <s:if test="#page.currentPage > 1">
					<a
						href="javascript:topage('<s:property value="#page.currentPage - 1"/>');">上一页</a>
				</s:if> <s:else>
					  上一页
				</s:else>
			</span>
			<s:if test="#page.totalPage>7">
				<s:if test="4>#page.currentPage">
					<s:iterator begin="1" end="4" step="1" status="i">
						<s:if test="#page.currentPage==#i.index+1">
							<a
								href='javascript:topageClass(<s:property value="#i.index+1"/>,<s:property value="#i.index+1"/>);'
								class="page_num active" id='<s:property value="#i.index+1"/>'><s:property
									value="#i.index+1" /></a>
						</s:if>
						<s:else>
							<a
								href='javascript:topageClass(<s:property value="#i.index+1"/>,<s:property value="#i.index+1"/>);'
								class="page_num" id='<s:property value="#i.index+1"/>'><s:property
									value="#i.index+1" /></a>
						</s:else>
					</s:iterator>
				</s:if>
				<s:elseif test="4==#page.currentPage">
					<s:iterator begin="1" end="4" step="1" status="i">
						<s:if test="#page.currentPage==#i.index+1">
							<a
								href='javascript:topageClass(<s:property value="#i.index+1"/>,<s:property value="#i.index+1"/>);'
								class="page_num active" id='<s:property value="#i.index+1"/>'><s:property
									value="#i.index+1" /></a>
						</s:if>
						<s:else>
							<a
								href='javascript:topageClass(<s:property value="#i.index+1"/>,<s:property value="#i.index+1"/>);'
								class="page_num" id='<s:property value="#i.index+1"/>'><s:property
									value="#i.index+1" /></a>
						</s:else>
					</s:iterator>
				</s:elseif>
				<s:else>
					<a href='javascript:topageClass(1,1);' class="page_num" id='1'><s:property value="1" /></a>
					<span class="page_num" >...</span>
					<s:if test="#page.totalPage==#page.currentPage">
					<a href='javascript:topageClass(<s:property value="#page.currentPage-3"/>,<s:property value="#page.currentPage-3"/>);'
					   class="page_num" id='<s:property value="#page.currentPage-3"/>'><s:property value="#page.currentPage-3" /></a>
					</s:if>
					<a href='javascript:topageClass(<s:property value="#page.currentPage-2"/>,<s:property value="#page.currentPage-2"/>);'
					   class="page_num" id='<s:property value="#page.currentPage-2"/>'><s:property value="#page.currentPage-2" /></a>
					<a href='javascript:topageClass(<s:property value="#page.currentPage-1"/>,<s:property value="#page.currentPage-1"/>);'
					   class="page_num" id='<s:property value="#page.currentPage-1"/>'><s:property value="#page.currentPage-1" /></a>
					<a href='javascript:topageClass(<s:property value="#page.currentPage"/>,<s:property value="#page.currentPage"/>);'
					   class="page_num active" id='<s:property value="#page.currentPage"/>'><s:property value="#page.currentPage" /></a>
				</s:else>
				<s:if test="#page.totalPage>#page.currentPage and #page.currentPage>3">
					<a href='javascript:topageClass(<s:property value="#page.currentPage+1"/>,<s:property value="#page.currentPage+1"/>);'
					   class="page_num" id='<s:property value="#page.currentPage+1"/>'><s:property value="#page.currentPage+1" /></a>
				</s:if>
				<s:if test="#page.currentPage+2>=#page.totalPage">
					<s:if test="#page.currentPage+2==#page.totalPage">
						<a href='javascript:topageClass(<s:property value="#page.currentPage+2"/>,<s:property value="#page.currentPage+2"/>);'
						   class="page_num" id='<s:property value="#page.currentPage+2"/>'><s:property value="#page.currentPage+2" /></a>
					</s:if>
				</s:if>
				<s:else>
					<span class="page_num" >...</span>
					<a href='javascript:topageClass(<s:property value="#page.totalPage"/>,<s:property value="#page.totalPage"/>);'
					   class="page_num" id='<s:property value="#page.totalPage"/>'><s:property value="#page.totalPage" /></a>
					
				</s:else>
			</s:if>
			<s:else>
				<s:iterator begin="1" end="#page.totalPage" step="1" status="i">
					<s:if test="#page.currentPage==#i.index+1">
						<a
							href='javascript:topageClass(<s:property value="#i.index+1"/>,<s:property value="#i.index+1"/>);'
							class="page_num active" id='<s:property value="#i.index+1"/>'><s:property
								value="#i.index+1" /></a>
					</s:if>
					<s:else>
						<a
							href='javascript:topageClass(<s:property value="#i.index+1"/>,<s:property value="#i.index+1"/>);'
							class="page_num" id='<s:property value="#i.index+1"/>'><s:property
								value="#i.index+1" /></a>
					</s:else>
				</s:iterator>
			</s:else>
			<span class="next_page"> <s:if
					test="#page.currentPage < #page.totalPage">
					<a
						href="javascript:topage('<s:property value="#page.currentPage + 1"/>');">下一页</a>
				</s:if> <s:else>
					  下一页
				</s:else>
			</span>
		</p>
	</div>
</s:if>